<?php

use yii\db\Schema;
use yii\db\Migration;

class m170516_050407_add_cod_banner_templates extends Migration
{
    public function up()
    {
        $clienImps = '//bsch.serving-sys.com/BurstingPipe/adServer.bs?cn=tf&c=19&mc=imp&pli=21421311&PluID=0&ord=%5Btimestamp%5D&rtu=-1';
        $impUrls = [
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSI&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSJ&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSK&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSL&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSM&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSN&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSO&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSP&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSQ&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSR&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSS&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WST&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSU&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSV&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSW&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSX&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSY&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSZ&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSa&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSb&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSc&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSd&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSe&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSf&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSg&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSh&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSi&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSj&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSk&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSl&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSm&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSn&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSo&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSp&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSq&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSr&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSs&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSt&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSu&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSv&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSw&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSx&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSy&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WSz&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WT0&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WT1&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WT2&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WT3&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WT4&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
            '//g.cn.miaozhen.com/x/k=2047006&p=76WT5&dx=__IPDX__&rt=2&ns=__IP__&ni=__IESID__&v=__LOC__&xa=__ADPLATFORM__&tr=__REQUESTID__&o=',
        ];
        $sql = "insert into {{%creative_template}} (name, code) values ";
        $values = [];
        for ($i=51; $i <101; $i++) {
            $index = $i - 51;
            $impUrl = $impUrls[$index];
            $template = <<<FINE
<div class="am_ad_container" style="position: relative; display: inline-block; border: none; padding: 0px; margin: 0px; visibility: visible; overflow: hidden;">
    <img src="{!dsp_show_url}" style="display:none;" />
    <img src="$clienImps" style="display:none;" />
    <img src="$impUrl" style="display:none;" />
    <script type="text/javascript" charset="utf-8">
        am_id = "{!dsp_creative_id}";
        am_tp = "{!dsp_creative_type}";
        am_wt = "{!dsp_creative_width}";
        am_ht = "{!dsp_creative_height}";
        am_ml = "{!dsp_creative_material}";
        am_ck = "{!vam_click_url}{!dsp_click_url}{!dsp_creative_monitor}{!dsp_creative_landingpage}";
        am_impr = "{!dsp_creative_impr}";
        am_logo = "{!dsp_creative_logo}";
    </script>
    <script type="text/javascript" charset="utf-8" class="ads_power_by_admath" id="am_{!dsp_creative_id}{!dsp_creative_width}{!dsp_creative_height}"
      src="{!dsp_cdn_url}/am_d.js"></script>
</div>
FINE;
            $name = 'Banner_'.$i;
            $values[] = "('$name', '$template')";
        }
        $sql .= implode($values, ',');
        $sql .= ';';
        return $this->execute($sql);
    }

    public function down()
    {
        echo "m170516_050407_add_cod_banner_templates cannot be reverted.\n";

        return false;
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
